package com.weilele.mvvm.widget

import android.content.Context
import android.util.AttributeSet
import com.google.android.material.textfield.TextInputEditText
import com.weilele.mvvm.R
import com.weilele.mvvm.widget.helper.setFontFromAssets

/**
 * 描述：
 */
open class BaseEditText : TextInputEditText {
    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
        handleTextViewAttribute(attrs)
    }

    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
        handleTextViewAttribute(attrs)
    }

    private fun handleTextViewAttribute(attributes: AttributeSet?) {
        context.obtainStyledAttributes(attributes, R.styleable.BaseEditText).apply {
            val fontPath = getString(R.styleable.BaseEditText_fontAssetsPath)
            if (!fontPath.isNullOrBlank()) {
                setFontFromAssets(fontPath)
            }
        }.recycle()
    }
}